package com.vinaprime.primeschedule.businesslayer;

import java.text.DateFormat;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.vinaprime.primeschedule.databaselayer.VPConfiguration_DL;
import com.vinaprime.primeschedule.databaselayer.VPLanguage_DL;
import com.vinaprime.primeschedule.databaselayer.VPSnoozeSound_DL;
import com.vinaprime.primeschedule.entities.VPConfiguration;
import com.vinaprime.primeschedule.entities.VPLanguage;
import com.vinaprime.primeschedule.entities.VPSnoozeSound;

public class VPConfiguration_BL {

	private VPConfiguration_DL myVPConfigDL;
	
	public VPConfiguration_BL(Context context, String path)
	{
		this.myVPConfigDL = new VPConfiguration_DL(context, path);
	}
	
	public VPConfiguration getConfiguration(){
		VPConfiguration config = new VPConfiguration();
		VPLanguage lang;
		VPSnoozeSound snoo;
		
		Cursor cur = this.myVPConfigDL.getConfiguration();
		
		if(cur.moveToFirst())
		{
			cur.moveToFirst();
			
			lang = new VPLanguage();
			snoo = new VPSnoozeSound();
			
			config.setVpcId(Integer.parseInt(cur.getString(cur.getColumnIndexOrThrow(VPConfiguration_DL.getDbTableColId()))));
			config.setVpcEmail(cur.getString(cur.getColumnIndexOrThrow(VPConfiguration_DL.getDbTableColEmail())));
			config.setVpcForceStopFlag(cur.getString(cur.getColumnIndexOrThrow(VPConfiguration_DL.getDbTableColForceStopFlag())));
			
			lang.setVplId(Integer.parseInt(cur.getString(cur.getColumnIndexOrThrow(VPConfiguration_DL.getDbTableColLanguageId()))));
			lang.setVplCode(cur.getString(cur.getColumnIndexOrThrow(VPLanguage_DL.getDbTableColCode())));
			lang.setVplName(cur.getString(cur.getColumnIndexOrThrow(VPLanguage_DL.getDbTableColName())));
			
			snoo.setVpssId(Integer.parseInt(cur.getString(cur.getColumnIndexOrThrow(VPConfiguration_DL.getDbTableColSnoozeSoundId()))));
			snoo.setVpssFilePath(cur.getString(cur.getColumnIndexOrThrow(VPSnoozeSound_DL.getDbVpssFilePath())));
			
			config.setVpcLanguage(lang);
			config.setVpcSnoozeSound(snoo);
		}
		
		return config;
	}
	
	public void updateConfiguration(VPConfiguration config){
		this.myVPConfigDL.updateConfiguration(config);
	}
}
